// pages/monthReportEdit/monthReportEdit.js
const app = getApp()
const api = app.globalData.api
Page({

  /**
   * 页面的初始数据
   */
  data: {
    level:[],
    level_selected:'',
    radio:'通过',
    audit_popup_show:false,
    weeArray:['日','一','二','三','四','五','六'],
    dayArr:[],
    fileList:[],
    steps: [],
    active:0
  },
edit(){
  wx.navigateTo({
    url: '../dayReportEdit/dayReportEdit?id='+this.data.info.id
  })

},
/**提交审核 */
commitAudit(){
  let id = this.data.info.id;
  api.curlPost('?cla=workReportApp&fun=commitAudit',{id:id}).then((res)=>{
    wx.navigateTo({
      url: '../workReport/workReport'
    })
  })
},
/**审阅 */
audit(){
  let id = this.data.info.id;
  let that = this;
  api.curlPost('?cla=workReportApp&fun=getAuditPage',{id:id}).then((res)=>{
    that.setData({
      audit_popup_show:true,
      level:res.data.level
    })
  })
},
/**选择日期 */
chooseDate(e){
  this.requstData(e.currentTarget.dataset.date)
},
/**切换月份 */
changeMonth(e){
  let type = e.currentTarget.dataset.type;
  let month = this.data.now_month;
  if(type=='pre'){
    month=api.getPreMonth(api.formatDateCRM('Y/m',month));
  }else if(type=='next'){
    month=api.getNextMonth(api.formatDateCRM('Y/m',month));
  }
  //请求数据
  this.requstData('',month)
},
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(api.isBlank(options.id)){
      wx.showToast({
        title: '未找到ID',
        icon: 'none',
      })
      setTimeout(function(){
        wx.navigateBack({
          delta: 1,
        })
      },3000)
   } else{
    this.requstData('','',options.id)//a8265a2e886e9d71
   }
  
   
  },
  requstData(date='',month='',id=''){
    let that = this;
    api.curlPost('?cla=workReportApp&fun=detail',{type:'日报',id:id,date:date,month:month}).then((res)=>{
      // if(api.isBlank(res.data.result.id)){
      //   wx.showToast({
      //     icon:'none',
      //     title: '未找到此报告',
      //   })
      // }else{
        that.setData({
          info:res.data.result,
          dayArr:res.data.result.dayRecord,
          now_month:res.data.result.now_month,
          now_date:res.data.result.now_date,
          now_month_text:api.formatDateCRM('Y年m月',res.data.result.now_month),
          fileList:res.data.result.attachFile?res.data.result.attachFile:[],
          steps:res.data.result.auditRecord,
          active:res.data.result.active
        })
      // }
      
    })
  },
  cancel(){
    this.setData({
      audit_popup_show:false
    })
  },
  /**提交审核 */
  auditComplete(e){
    let id = this.data.info.id;
    let para = e.detail.value;
    para.id = id;
    let that = this;
    api.curlPost('?cla=workReportApp&fun=review',para).then((res)=>{
      wx.navigateTo({
        url: '../workReport/workReport',
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})